package com.jzbooks.result;

import com.jzbooks.enums.ResultCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * @author mingPeng
 * @date 2021/4/19 18:17
 * @Description :  返回结果格式
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PlatformResult implements Serializable {
    /**
     * 自定义状态码
     */
    private Integer code;
    /**
     * 自定义消息
     */
    private String msg;
    /**
     * 返回数据
     */
    private Object data;

    private void setPlatformResult(ResultCodeEnum resultCodeEnum){
        this.code=resultCodeEnum.getCode();
        this.msg=resultCodeEnum.getMsg();
    }

    public PlatformResult success(){
        PlatformResult platformResult=new PlatformResult();
        platformResult.setPlatformResult(ResultCodeEnum.SUCCESS);
        return platformResult;
    }

    public static PlatformResult success(Object data){
        PlatformResult platformResult=new PlatformResult();
        platformResult.setPlatformResult(ResultCodeEnum.SUCCESS);
        platformResult.setData(data);
        return platformResult;
    }

    public static PlatformResult failure(ResultCodeEnum resultCodeEnum){
        PlatformResult platformResult=new PlatformResult();
        platformResult.setPlatformResult(ResultCodeEnum.Fail);
        return platformResult;
    }

    public static PlatformResult failure(ResultCodeEnum resultCodeEnum,Object data){
        PlatformResult platformResult=new PlatformResult();
        platformResult.setPlatformResult(ResultCodeEnum.Fail);
        platformResult.setData(data);
        return platformResult;
    }

}
